The SUIP Kitchen
I started work on the GUI for the sorting machine this past week. The GUI for the server has been code-named SUIP; "Sorting User Interface Program". It runs as it's own process, so it's decoupled from the server. If one crashes, the other keeps running. I have some clever ideas for crash handling that a professional might find amusing; but that's for another day.
In my most recent article I said:
"...I predict that implementing the SUIP will involve alcohol, re-writing large chunks of the server, and some amount of profanity."
I was wrong. Strangely wrong. Alcohol hasn't been required, and the server has hardly needed modification to accept the SUIP. Indeed the difficulties I encountered were of a more bureaucratic nature.
Automate the boring stuff!
I began by researching the different GUI platforms out there. I settled on QT, which is well documented and seems no more or less challenging to use than any other GUI framework. There are implementations of QT for Python and C++ (and probably other languages too) and I had a simple GUI running with a cute little button and an SQL table showing live data from the server in just a few hours.
A GUI is essentially a tree. You have a main window that defines the total area you have to work in, and then each menu, box, button, bar, text box, etc. branch off of the main window, and the various sub-menus and popup windows get attached to whatever element leads to them.
The tricky part is that the code needs to define each branch and leaf of your GUI tree in a strict top to bottom sequence. To get an idea what that's like, try describing your family tree only using parental relationships, one line at a time.
- Your father and mother had child 1
- Your father and mother had child 2
- Your father and mother had child 3
- Your father and mother had child 4
- Your father and mother had child 5
- Child 1 married spouse 1
- Child 1 and Spouse 1 had grandchild 1
And so on and so forth until.....
- Child 5 and spouse 4 had grandchild 6
This could easily become hundreds of lines or more for large families, and it would be very easy to miss someone. The solution here is to have a program do the leg work for you. I decide on window sizes, button labels, and text box contents using a design program, and that program exports code for me to add to the SUIP. Simple right?
Well, sort of
The folks at QT have a free offering of their development suite, which is not as well featured as the paid version but still affords a decent amount capability. I only wanted the QT designer, but you get the whole development suite in one download, so I dove in. The designer is a comparatively small component of the QT package (which includes and IDE, publishing tools, plugins, and a host other stuff that I don't need). Primarily QT designer lets you use a nice graphical interface to create your windows, buttons, boxes etc and then it writes the code for you to define their relationships.
This allows me to see what I'm doing in real time instead of sticking bits of code together and running the server over and over. I made significantly faster progression on the SUIP with this software, once it was installed.
It started innocently enough, I had downloaded the installer, selected a suitable directory and choose the default packages, not knowing which parts I needed and which parts I didn't.
It began to download packages. I have a gigabit internet connection so this shouldn't take more than a minute or two. At first I thought they must have a slow repository, it said it will take 40 minutes to download. Oh well, no big deal. It was 11:17pm, and I had nowhere to be.
I watched this very screen you see here, scroll by with strange files being copied to my overburdened disk for over an hour and a half. It was only at 43%. I went to bed. I checked the install logs in the morning and found that installer finished its' work around 4:30AM.
That's 35 Gigabytes, and 358,196 files. That's twice the disk space and more than quadruple the time needed to install Windows 10. Cool.
On the plus side, I now have a delightful UI which contains tabs, tables, button and more. QT designer creates C++ code, but the python QT library has a nifty tool for converting it to raw python. The resulting code is then transplanted and in to my code and surgically connected. All in all, it's way better than making all the GUI bits by hand.
Here's a peek of what the server looks like while running, it's not pretty and is missing many features, but it works well so far. This is just a view for debugging and monitoring the server. The actual interface for sorting might possibly look a little nicer, maybe.